// pages/editinvoice/editinvoice.js

import Dialog from '../../miniprogram_npm/@vant/weapp/dialog/dialog';
import api from "../../utils/api";

Page({

  /**
   * 页面的初始数据
   */
  data: {
    id: '',
    coId: '',
    uuid: '',
    unitId: '',
    show: false,
    showType: false,
    showType_yewu: false,
    columns: [], //下拉选
    columns2: [], //下拉选
    columns_yewu: [],
    radio: '', //是否到款
    receiveType: '', //到款类型
    label: '1',
    is_cpyjf: '0', // 产品已交付
    radio2: '', //是否关联合同
    code: '',
    userName: '',
    deptName: '',
    deptId: '',
    fpTypeStr: '',
    fpType: '', //发票
    cusId: '', //单位id
    money: '',
    tax: '',
    // isReceived: '',
    date: '2023/12/31', //到款日期
    getTime: '', //转时间戳之后
    receTermCode: '', //到款项code

    keyId: '', //税率
    dictKey: '', //发票类型
    dictKey2: '', //到款类型
    businessTypeStr: '', //业务类型
    businessType: '',
    flowStatus: '',
    invFormContentList: '', //开票内容列表
    sysDictContractList: '', //合同列表
    invFormTaskList: '', //合同任务号列表
    sysDictCustomerList: '', //往来单位
    sysDictCustomer: [{
      itin: '',
      address: '',
      openingBank: '',
      bankAccount: '',
    }],
    saveButton: '',
    minDate: '',
    maxDate: '',
    invtaxRate: '', //该发票税率

    fileList: [],
    ContractReason: false, //无合同原因

    kaipiaoneirong: true, //开票内容显示与否
    offlineYearClaimed: '', // 是否显示该字段 线下或往年已认领
    isOfflineYearClaimed: '0', //该字段默认
  },
  //业务类型
  businessType(event) {
    // console.log(event, "业务类型")
    this.setData({
      showType_yewu: true
    });
    this.businessTypeList()

  },
  //业务类型列表初始渲染
  businessTypeList() {
    let that = this;
    api.getBusinessTypeList({
      data: {
        coId: that.data.coId,
      },
      success: function (res) {
        console.log(res.data.data, "业务类型")
        if (res.data.code = 200) {
          that.data.columns_yewu = [];
          if (res.data.data.length > 0) {
            res.data.data.forEach((item) => {
              let obj = {
                text: item.dictValue,
                businessType: item.dictKey,
                // dictValue02: item.dictValue02,
              }
              that.data.columns_yewu.push(obj)
              // console.log(that.data.columns_yewu, 'oooo')
            });
            that.setData({
              columns_yewu: that.data.columns_yewu,
              showType_yewu: true
            })
          } else {
            that.setData({
              showType_yewu: false
            })
          }

        }
      }
    })
  },
  onCancelType_yw() {
    this.setData({
      showType_yewu: false
    });
  },
  onConfirmType_yw(e) {
    const {
      value,
    } = e.detail;
    console.log(value, "val")
    let text = value.text;
    this.data.businessType = value.businessType;
    this.setData({
      businessTypeStr: value.text,
      businessType: this.data.businessType,
      showType_yewu: false,
    })
    console.log(this.data.businessType)
  },

  focus(e) {
    console.log(e.detail.value, "focus")
    this.setData({
      showType: true,
      fpTypeStr: e.detail.value
    });
    this.showList()

    // if(e.detail.value == e.detail.value){
    //   this.showList()
    // }
  },
  change(e) {
    console.log(e.detail, "change")
    this.setData({
      showType: true,
      fpTypeStr: e.detail
    });
    this.showList()
  },
  click(e) {
    this.setData({
      fpTypeStr: ''
    })
    this.showList()
  },
  //发票类型列表初始页面渲染
  showList() {
    let that = this;
    api.addNewinvType({
      data: {
        coId: this.data.coId,
        word: this.data.fpTypeStr,
      },
      success: function (res) {
        console.log(res.data.data, "addNewinvType")
        if (res.data.code = 200) {
          that.data.columns = [];
          res.data.data.forEach((item) => {
            let obj = {
              text: item.dictValue,
              keyId: item.dictValue02,
              dictKey: item.dictKey
            }
            that.data.columns.push(obj)
            console.log(that.data.columns, 'oooo')
          });
          that.setData({
            columns: that.data.columns,
          })
          that.setData({
            showType: true
          })
        }
      }
    })
  },
  onCancelType() {
    this.setData({
      showType: false
    });
  },
  onConfirmType(e) {
    const {
      value,
    } = e.detail;
    console.log(value, "val")
    //选择最后一个（收据）时，开票内容不显示
    // if (value.dictKey == 8) {
    //   console.log('选择 收据--开票内容不显示')
    //   this.setData({
    //     kaipiaoneirong: false,
    //   })
    // } else {
    //   this.setData({
    //     kaipiaoneirong: true,
    //   })
    // }

    let keyId = value.keyId
    let text = value.text;
    let dictKey = value.dictKey
    this.data.keyId = keyId;
    this.data.dictKey = dictKey;
    this.setData({
      fpTypeStr: value.text,
      fpType: this.data.dictKey,
      showType: false,
    })
  },
  //输入开票金额自动计算税款
  onfieldChange(e) {
    if (this.data.fpTypeStr != '') {
      this.setData({
        money: e.detail,
        tax: (e.detail * this.data.keyId).toFixed(2)
      })
    } else {
      wx.showToast({
        title: '请先选择发票类型',
        icon: 'none'
      })
    }


  },
  //是否到款 单选框改变
  onradioChange(event) {
    console.log(event.detail)
    //是否到款 （否）1.清缓存（id 和 code）  2.id置为空  3.code置为空
    if (event.detail == 0) {
      wx.removeStorageSync('receTerm2');
      wx.removeStorageSync('receTerm');
      wx.removeStorageSync('dkClaimId');
      wx.removeStorageSync('receiveId');

      this.data.receiveId = ''
      this.data.dkClaimId = ''
      console.log(this.data.receiveId)
      console.log(this.data.dkClaimId)

      this.setData({
        receTermCode: '',
        isOfflineYearClaimed: '', //该字段默认显示为空
      });

    }
    if (event.detail == 1) {
      this.setData({
        label: event.detail,
        dictKey2: '',
        // receiveType:''
        offlineYearClaimed: 1,
      });
    } else {
      this.setData({
        label: event.detail,
        dictKey2: '',
        // receiveType:''

      });
    }
    this.setData({
      radio: event.detail,
    });
    this.save()
  },
  onradioTypefocus(e) {
    console.log(e.detail.value, "ppp")
    this.setData({
      showType2: true,
      receiveType: e.detail.value
    });
    this.showListType()
    // if (e.detail.value == '') {
    //   this.showListType()
    // }
  },
  onradioTypeChange(event) {
    this.setData({
      showType2: true,
      receiveType: event.detail
    })
    this.showListType()
  },
  onradioTypeclick(e) {
    console.log(e)
    this.showListType()
  },
  //4.27新增 线下或往年已认领 单选框
  onoffChange(event) {
    this.setData({
      isOfflineYearClaimed: event.detail,
    })
    const that = this;
    console.log(event.detail, '线下或往年已认领')
    // 是 1 到款项不显示 到款日期默认(2022.1.1) 到款类型默认（线下或往年已认领 receiveType=7） 
    if (event.detail == 1) {
      this.data.receiveId = ''
      this.data.dkClaimId = ''
      this.setData({
        date: that.formatDate(new Date(`${new Date().getFullYear()-1}/12/31`)),
        receiveType: '线下或往年已认领',
        dictKey2: "7", //到款类型默认为 线下或往年已认领
      })
    }
    if (event.detail == 0) {
      wx.removeStorageSync('receTerm2');
      wx.removeStorageSync('receTerm');
      wx.removeStorageSync('dkClaimId');
      wx.removeStorageSync('receiveId');

      this.data.receiveId = ''
      this.data.dkClaimId = ''
      this.setData({
        receTermCode: '',
      });

      this.setData({
        date: that.formatDate(new Date()),
        receiveType: '',
        dictKey2: '', //到款类型默认为 线下或往年已认领
      })
    }
    this.save()

  },


  //到款类型列表初始页面渲染
  showListType() {
    let that = this;
    api.getBankTypeList({
      data: {
        coId: this.data.coId,
        // word: this.data.receiveType,
      },
      success: function (res) {
        console.log(res.data.data, "getBankTypeList")
        if (res.data.code == 200) {
          if (res.data.data.length > 0) {
            res.data.data.forEach((item) => {
              let obj = {
                text: item.dictValue,
                dictKey2: item.dictKey
              }
              that.data.columns2.push(obj)
              // console.log(that.data.columns2, 'oooo')
            });
            that.setData({
              columns2: that.data.columns2,
            })
            that.setData({
              showType2: true
            })
          } else {
            that.setData({
              showType2: false
            })
          }

        }
      }
    })
  },
  onCancelType2() {
    this.setData({
      showType2: false
    });
  },
  onConfirmType2(e) {
    const {
      value,
    } = e.detail;
    console.log(value, "val")
    let text = value.text;
    let dictKey2 = value.dictKey2
    this.data.dictKey2 = dictKey2;
    this.setData({
      receiveType: value.text,
      showType2: false,
    })
  },
  handlecpyjf(event) {
    console.log(event.detail, "产品已交付")
    this.setData({
      is_cpyjf: event.detail
    })
  },
  //单选框改变2（是否关联合同）
  onradio2Change(event) {
    console.log(event.detail, '是否关联合同')
    //否关联合同的时候显示无合同原因
    if (event.detail == 0) {
      this.setData({
        ContractReason: true
      })
    }
    this.setData({
      radio2: event.detail,
      noContractReason: '',
    });
    this.save()
  },
  //选择到款项 点击跳转
  onreceTermChange() {
    wx.navigateTo({
      url: '/pages/selectReceived/selectReceived?money=' + this.data.money + '&id=' + this.data.id + '&from=' + 2,
    })
  },
  //日期弹框
  onDisplay() {
    this.setData({
      minDate: new Date(2018, 0, 1).getTime(),
      maxDate: new Date(2028, 0, 31).getTime(),
      show: true
    });
  },
  onClose() {
    this.setData({
      show: false
    });
  },
  formatDate(date) {
    this.setData({
      getTime: date
    })

    date = new Date(date);
    return `${date.getFullYear()}/${date.getMonth() + 1}/${date.getDate()}`;
  },
  onConfirm(event) {
    this.setData({
      show: false,
      date: this.formatDate(event.detail),
    });
  },
  //无合同原因
  noContractReasonChange(e) {
    console.log(e.detail, '无合同原因')
    this.setData({
      noContractReason: e.detail,
    });
    //  this.save()
  },
  noContractReasonblur() {
    this.save()
  },
  //备注
  onremarksChange(e) {
    console.log(e.detail)
    this.setData({
      remarks: e.detail,
    });
  },
  // //导入开票内容
  afterRead(event) {
    let that = this
    console.log(event.detail, '导入开票内容')
    const {
      file
    } = event.detail;
    // console.log(file[0].url)
    wx.uploadFile({
      method: 'POST',
      url: 'https://api.gm.gmread.cn/payment_api/inv/content/excelImport',
      filePath: file[0].url,
      name: 'file',
      formData: {
        coId: this.data.coId,
        userId: this.data.unitId,
        invId: this.data.id,
        taxRate: this.data.keyId,
      },
      header: {
        'Content-Type': 'multipart/form-data',
        'Authorization': wx.getStorageSync('userToken') ? wx.getStorageSync('userToken') : ''
      },
      success(res) {
        console.log(res, '导入')
        let resData = JSON.parse(res.data)
        if (resData.code == 200) {
          that.getDate()
          that.sumMoneyByInvId()
          wx.showToast({
            title: resData.data,
          })
        } else {
          wx.showToast({
            title: resData.data,
          })
        }
      },
      fail(res) {
        console.log(res, '失败')
      }
    });
  },
  //开票内容总金额
  sumMoneyByInvId() {
    let that = this;
    api.sumMoneyByInvId({
      data: {
        invId: this.data.id,
      },
      success: function (res) {
        console.log(res.data.data, "开票内容总金额")
        if (res.data.code == 200) {
          that.setData({
            total: res.data.data
          })
        }
      }
    })
  },

  //点击开票内容+
  addkaipiao() {
    wx.navigateTo({
      url: '/pages/newtask/newtask?id= ' + this.data.id + '&code=' + this.data.code + '&keyId=' + this.data.keyId + '&userName=' + this.data.userName + '&deptName=' + this.data.deptName,
    })
  },
  //点击合同+
  addhetong() {
    wx.navigateTo({
      url: '/pages/newbill/newbill?id= ' + this.data.id + '&unitId=' + this.data.unitId + '&cusId=' + this.data.cusId,
    })
  },
  //点击任务号+
  addrenwuhao() {
    wx.navigateTo({
      url: '/pages/addrenwuhao/addrenwuhao?id= ' + this.data.id + '&unitId=' + this.data.unitId + '&cusId=' + this.data.cusId + '&invtaxRate=' + this.data.invtaxRate,
    })
  },
  //点击往来单位+
  addwanglaidw() {
    // from=2 从编辑发票页面点击
    wx.navigateTo({
      url: '/pages/intercourseUnit/intercourseUnit?from= ' + 2 + '&invid=' + this.data.id,
    })
  },
  //点击  跳转到开票内容详情
  clickItem(e) {
    console.log(e.currentTarget.dataset.id, "pppppp")
    wx.navigateTo({
      url: '/pages/invContdetails/invContdetails?id= ' + e.currentTarget.dataset.id + '&saveButton=' + this.data.saveButton,
    })
  },
  //点击  跳转到合同详情
  clickItemcon(e) {
    // console.log(e.currentTarget.dataset.id, '!!!')
    wx.navigateTo({
      url: '/pages/taskNumdetails/taskNumdetails?id= ' + e.currentTarget.dataset.id + '&saveButton=' + this.data.saveButton,
    })
  },
  //点击  跳转到任务号详情
  clickrenwuhao(e) {
    // console.log(e.currentTarget.dataset.id, '!!!')
    wx.navigateTo({
      url: '/pages/taskNumdetails/taskNumdetails?id= ' + e.currentTarget.dataset.id + '&saveButton=' + this.data.saveButton,
    })
  },
  //税号 
  onitinChange(event) {
    this.setData(
      this.data.sysDictCustomer[0].itin = event.detail
    )
  },
  //地址 
  onaddressChange(event) {
    this.setData(
      this.data.sysDictCustomer[0].address = event.detail
    )
  },
  //开户行 
  onopeningBankChange(event) {
    this.setData(
      this.data.sysDictCustomer[0].openingBank = event.detail
    )
  },
  //银行卡号 
  onbankAccountChange(event) {
    this.setData(
      this.data.sysDictCustomer[0].bankAccount = event.detail
    )
  },
  //保存
  save() {
    if (this.data.radio2 == 0 && this.data.noContractReason == '') {
      wx.showToast({
        title: '请输入无合同原因',
        icon: 'none'
      })
    }
    // console.log(this.data.noContractReason,"lll")
    this.setData({
      sysDictCustomer: this.data.sysDictCustomer
    })

    console.log(this.data.sysDictCustomer)
    let that = this;

    api.invEdit({
      method: 'post',
      data: {
        id: this.data.id,
        updateBy: this.data.unitId,
        fpType: this.data.fpType,
        taxRate: this.data.keyId,
        money: this.data.money,
        cusId: this.data.cusId,
        isReceived: this.data.radio,
        //到款项id
        receiveId: this.data.receiveId,
        dkClaimId: this.data.dkClaimId,

        receiveType: that.data.dictKey2,
        needContract: parseInt(this.data.radio2), //是否关联合同
        receiveDate: this.data.getTime,
        is_cpyjf: this.data.is_cpyjf,
        remarks: this.data.remarks, //备注
        sysDictCustomer: this.data.sysDictCustomer,
        businessType: this.data.businessType,
        noContractReason: this.data.noContractReason, //无合同原因
        isOfflineClaimed: this.data.isOfflineYearClaimed // 线下或往年已认领 是否
      },
      success: function (res) {
        // console.log(res.data.data, "invEdit")
        if (res.data.code == 200) {
          // wx.showToast({
          //   title: '保存成功',
          //   icon: 'success'
          // })
          that.getDate()
        }
      }
    })
    // this.getDate()
  },
  //提交
  submit() {
    this.save()
    setTimeout(() => {
      let that = this;
      api.invSubmit({
        method: 'post',
        data: {
          coId: this.data.coId,
          uuid: this.data.uuid,
          invId: this.data.id,
          deptId: this.data.deptId,
          userId: this.data.unitId,
        },
        success: function (res) {
          console.log(res.data.data, "invEdit")
          if (res.data.code == 200) {
            wx.showModal({
              content: '发票提交成功',
              showCancel: false,
              confirmColor: '#0041C4',
              success: function (res) {
                if (res.confirm) {
                  setTimeout(() => {
                    wx.navigateBack({
                      delta: 1,
                    })
                  }, 100);
                }
              }
            })
          } else {
            wx.showModal({
              content: res.data.message,
              showCancel: false,
              confirmColor: '#0041C4'
            })
          }
        }
      })
    }, 1000);


  },
  //再次提交
  resubmit() {
    this.save()
    setTimeout(() => {
      let that = this;
      api.resubmit({
        method: 'post',
        data: {
          coId: this.data.coId,
          uuid: this.data.uuid,
          invId: this.data.id,
          deptId: this.data.deptId,
          userId: this.data.unitId,
        },
        success: function (res) {
          console.log(res.data.data, "resubmit")
          if (res.data.code == 200) {
            wx.showModal({
              content: '发票提交成功',
              showCancel: false,
              confirmColor: '#0041C4',
              success: function (res) {
                if (res.confirm) {
                  setTimeout(() => {
                    wx.navigateBack({
                      delta: 1,
                    })
                  }, 100);
                }
              }
            })
          } else {
            wx.showModal({
              content: res.data.message,
              showCancel: false,
              confirmColor: '#0041C4'
            })
          }
        }
      })
    }, 500);
  },

  getDate() {
    let that = this;
    api.invDetails({
      data: {
        id: this.data.id,
      },
      success: function (res) {
        console.log(res.data.data, "invDetails")
        if (res.data.code == 200) {
          //开票内容
          for (let i = 0; i < res.data.data.invFormContentList.length; i++) {
            res.data.data.invFormContentList[i].money = that.addComma(res.data.data.invFormContentList[i].money)
          }
          //合同
          for (let i = 0; i < res.data.data.sysDictContractList.length; i++) {
            res.data.data.sysDictContractList[i].waitMoney = that.addComma(res.data.data.sysDictContractList[i].waitMoney)
            res.data.data.sysDictContractList[i].money = that.addComma(res.data.data.sysDictContractList[i].money)
            if (res.data.data.sysDictContractList[i].invFormTaskList.length > 0) {
              let invFormTaskList = res.data.data.sysDictContractList[i];
              for (let items = 0; items < invFormTaskList.length; items++) {
                res.data.data.invFormTaskList[i].contTaskMoney = that.addComma(res.data.data.invFormTaskList[i].contTaskMoney)
                res.data.data.invFormTaskList[i].money = that.addComma(res.data.data.invFormTaskList[i].money)
              }
            }
          }
          //任务号
          for (let i = 0; i < res.data.data.invTaskList.length; i++) {
            res.data.data.invTaskList[i].money = that.addComma(res.data.data.invTaskList[i].money)
          }
          //往来单位
          for (let i = 0; i < res.data.data.sysDictCustomer.length; i++) {
            // res.data.data.sysDictCustomer[i].bankAccount = res.data.data.sysDictCustomer[i].bankAccount.toString().replace(/(.{4})/g, "$1 ")
          }
          // console.log(that.formatDate(res.data.data.receiveDate))
          that.setData({
            saveButton: res.data.data.saveButton,
            code: res.data.data.code,
            userName: res.data.data.userDept.userName,
            deptName: res.data.data.userDept.deptName,
            deptId: res.data.data.userDept.deptId,
            fpTypeStr: res.data.data.fpTypeStr,
            fpType: res.data.data.fpType,
            cusId: res.data.data.cusId,
            money: res.data.data.money,
            tax: res.data.data.money * res.data.data.taxRate,
            radio: res.data.data.isReceived, //是否到款  1 是 0 否
            receTermCode: res.data.data.receTermCode, //到款项
            receiveType: res.data.data.receiveTypeStr, //到款类型
            date: res.data.data.receiveDate ? that.formatDate(res.data.data.receiveDate) : res.data.data.isReceived == '0' || res.data.data.isOfflineClaimed == '0' ? that.formatDate(new Date()) : that.formatDate(new Date(`${new Date().getFullYear()-1}/12/31`)), //到款日期默认2022/1/1
            radio2: res.data.data.needContract.toString(), //是否关联合同
            is_cpyjf: res.data.data.is_cpyjf,
            remarks: res.data.data.remarks,
            keyId: res.data.data.taxRate,
            flowStatus: res.data.data.flowStatus,
            uuid: res.data.data.uuid,
            invFormContentList: res.data.data.invFormContentList, //开票内容
            sysDictContractList: res.data.data.sysDictContractList, //合同
            sysDictCustomer: res.data.data.sysDictCustomer, //往来单位
            invTaskList: res.data.data.invTaskList,
            invtaxRate: res.data.data.taxRateStr,
            businessTypeStr: res.data.data.businessTypeStr,
            businessType: res.data.data.businessType,
            noContractReason: res.data.data.noContractReason, //无合同原因
            isOfflineYearClaimed: res.data.data.isOfflineClaimed === "1" ? "1" : '0',
          })
          //
          if (res.data.data.isReceived == '1') {
            that.setData({
              offlineYearClaimed: '1'
            });
          } else {
            that.setData({
              offlineYearClaimed: ''
            });
          }
          if (res.data.data.isOfflineClaimed == 1) {
            that.setData({
              // radio:'0',//到款项不显示
              date: that.formatDate(new Date(`${new Date().getFullYear()-1}/12/31`)),
              receiveType: '线下或往年已认领',
              dictKey2: "7", //到款类型默认为 线下或往年已认领
            })
          }
          //
          // if (res.data.data.fpType == '8') {
          //   console.log('渲染 收据--不显示开票内容')
          //   that.setData({
          //     kaipiaoneirong: false,
          //   })
          // } else {
          //   that.setData({
          //     kaipiaoneirong: true,
          //   })
          // }
          //
          if (res.data.data.isReceived == "1") {
            that.setData({
              label: 1,
              dictKey2: res.data.data.receiveType
            });
          } else {
            // console.log('否')
            that.setData({
              label: 0,
              dictKey2: ''
            });
          }
        }
      }
    })


  },
  //删除开票内容list
  delkaipiao(e) {
    let index = e.currentTarget.dataset.index;
    let that = this
    Dialog.confirm({
        message: '确定删除吗？',
      })
      .then(() => {
        api.delkaipiao({
          data: {
            id: e.currentTarget.dataset.id
          },
          success: function (res) {
            if (res.data.code == 200) {
              that.sumMoneyByInvId()
              // console.log('删除开票内容list')
              that.data.invFormContentList.splice(index, 1)
              that.setData({
                invFormContentList: that.data.invFormContentList
              })
              wx.showToast({
                title: '删除成功',
                icon: 'success'
              })
            }
          }
        })
      })
      .catch(() => {
        // on cancel
        console.log('取消操作')
      });
  },
  //删除合同list
  delhetong(e) {
    let index = e.currentTarget.dataset.index;
    let that = this
    Dialog.confirm({
        message: '确定删除吗？',
      })
      .then(() => {
        api.delhetong({
          data: {
            id: e.currentTarget.dataset.id,
            invId: this.data.id
          },
          success: function (res) {
            if (res.data.code == 200) {
              console.log('yyds')
              that.data.sysDictContractList.splice(index, 1)
              that.setData({
                sysDictContractList: that.data.sysDictContractList
              })
              wx.showToast({
                title: '删除成功',
                icon: 'success'
              })
            }
          }
        })
      })
      .catch(() => {
        // on cancel
        console.log('取消操作')
      });
  },
  //删除任务号分摊list
  delfentan(e) {
    let index = e.currentTarget.dataset.index;
    let that = this
    Dialog.confirm({
        message: '确定删除吗？',
      })
      .then(() => {
        api.delfentan({
          data: {
            id: e.currentTarget.dataset.id
          },
          success: function (res) {
            if (res.data.code == 200) {
              // console.log('yyds')
              that.data.sysDictContractList.forEach((item) => {
                // console.log(item, "iten")
                item.invFormTaskList.splice(index, 1)
                that.setData({
                  sysDictContractList: that.data.sysDictContractList
                })
              })


              wx.showToast({
                title: '删除成功',
                icon: 'success'
              })
            }
          }
        })
      })
      .catch(() => {
        // on cancel
        // console.log('取消操作')
      });
  },
  //删除任务号list
  delrenwuhao(e) {
    let index = e.currentTarget.dataset.index;
    let that = this
    Dialog.confirm({
        message: '确定删除吗？',
      })
      .then(() => {
        api.delrenwuhao({
          data: {
            id: e.currentTarget.dataset.id,
          },
          success: function (res) {
            if (res.data.code == 200) {
              // console.log('yyds')
              that.data.invTaskList.splice(index, 1)
              that.setData({
                invTaskList: that.data.invTaskList
              })
              wx.showToast({
                title: '删除成功',
                icon: 'success'
              })
            }
          }
        })
      })
      .catch(() => {
        // on cancel
        // console.log('取消操作')
      });
  },

  //千分位 转换
  addComma(date) {
    let str = '';
    let num = '';
    let newStr = '';
    date = date + '';
    if (date.indexOf('.') != -1) {
      num = date.split('.')[0]
      str = date.split('.')[1]
    } else {
      num = date
    }
    newStr = num.toString().replace(/(\d)(?=(?:\d{3})+$)/g, '$1,');
    newStr = str == '' ? newStr : newStr + '.' + str;
    return newStr;
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    // console.log(options, 'options')
    this.setData({
      id: options.id,
      needContract: options.needContract
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {},

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.data.coId = wx.getStorageSync('userInfo').coId
    this.data.unitId = wx.getStorageSync('userInfo').unitId
    this.getDate()
    this.sumMoneyByInvId()

    // this.afterRead()
    //获取到的到款项code
    // console.log(this.data.receTermCode, '返回的到款项 有无')

    //   this.setData({
    //   receTermCode: this.data.receTermCodeRes ? this.data.receTermCodeRes : wx.getStorageSync('receTermCode') ,
    //  });
    // console.log(this.data.receTermCode, this.data.receTermCodeRes,'到款项')
    // if (wx.getStorageSync('receTerm')) {
    //   this.setData({
    //     receTermCode: wx.getStorageSync('receTerm'),
    //     // receiveType : wx.getStorageSync('bankType') ? wx.getStorageSync('bankType') :''
    //   });
    //   // console.log(this.data.receTermCode,'未认领')
    // } else if (wx.getStorageSync('receTerm2')) {
    //   this.setData({
    //     receTermCode: wx.getStorageSync('receTerm2')
    //   });
    //   // console.log(this.data.receTermCode,'已认领')
    // }
    this.data.receiveId = wx.getStorageSync('receiveId') ? wx.getStorageSync('receiveId') : '';
    this.data.dkClaimId = wx.getStorageSync('dkClaimId') ? wx.getStorageSync('dkClaimId') : '';

    // console.log(this.data.receiveId, "show")
    // console.log(this.data.dkClaimId, "show")

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})